package com.xuxueli.commontdemo.commont.testSocket;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

/**
 * 测试公司socket服务端
 */
public class TestServerSocketCompany {

    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(1123);
        Socket socket = serverSocket.accept();
        socket.setSoTimeout(10);//设置socket读超时时间10毫秒
        InputStream inputStream = socket.getInputStream();
        byte[] bytes = new byte[1024];
        int value = inputStream.read(bytes);
        System.out.println("客户端传来的数据："+new String(bytes,0,value,StandardCharsets.UTF_8));
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write(bytes,0,value);
    }
}
